// JavaScript Document

function selectAll(f) {
    var navigate_all = document.getElementById("navigate_all");
    var navigate_ids = document.getElementsByName("navigate_id");
    if(navigate_ids == null){
        return;
    }
    for(var i = 0;i < navigate_ids.length;i++){
		navigate_ids[i].checked = navigate_all.checked;
    }
	checkSelection(f);
}

function countIdChecked(){
	var navigate_ids = document.getElementsByName("navigate_id");

	var idchecked = 0;
	if(navigate_ids != null){
    	for(var i = 0;i < navigate_ids.length;i++){
    		if(navigate_ids[i].checked){
    			idchecked++;
    		}
    	}
	}
	return idchecked;
}

function checkSelection(){
	var navigate_all = document.getElementById("navigate_all");
	var navigate_ids = document.getElementsByName("navigate_id");
	
    if(navigate_ids == null || navigate_ids.length == 0){
        if(navigate_all == null){
            return;
        }
        var f = navigate_all.form;
		for (var i = 0; i < f.elements.length; i++) {
			if(f.elements[i].type == "button" || f.elements[i].type == "submit"){
				var ss = f.elements[i].getAttribute("selectionmode");
				if(ss == "one" || ss == "more"){
					f.elements[i].disabled = true;
				} else {
					f.elements[i].disabled = false;
				}
			}
		}
    } else {
        var f = navigate_ids[0].form;
    	var idchecked = countIdChecked();
	
        if(navigate_all != null){
        	if(idchecked == 0){
        		navigate_all.checked = false;
        	}
        	if(idchecked == navigate_ids.length){
        		navigate_all.checked = true;
        	}  
        }
    	
    	if(idchecked == 0){
    		for (var i = 0; i < f.elements.length; i++) {
    			if(f.elements[i].type == "button" || f.elements[i].type == "submit"){
    				var ss = f.elements[i].getAttribute("selectionmode");
    				if(ss == "one" || ss == "more"){
    					f.elements[i].disabled = true;
    				} else {
    					f.elements[i].disabled = false;
    				}
    			}
    		}
    	} else if(idchecked > 1){
    		for (var i = 0; i < f.elements.length; i++) {
    			if(f.elements[i].type == "button" || f.elements[i].type == "submit"){
    				var ss = f.elements[i].getAttribute("selectionmode");
    				if(ss == "one"){
    					f.elements[i].disabled = true;
    				} else {
    					f.elements[i].disabled = false;
    				}
    			}
    		}
    	} else {
    		for (var i = 0; i < f.elements.length; i++) {
    			if(f.elements[i].type == "button" || f.elements[i].type == "submit"){
    				f.elements[i].disabled = false;
    			}
    		}
    	}
    }
}